package com.y.architecture.base_refresh;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;

import com.y.architecture.R;
import com.y.architecture.base_header.BaseHeaderActivity;

/**
 * Created by youjingjing on 2017/11/27.
 */

public abstract class BaseRefreshActivity extends BaseHeaderActivity implements IBaseRefreshContact.IBaseRefreshView{

    protected SwipeRefreshLayout mSwipeRefreshLayout;
//    protected SpinKitView mSpinKitView;
    private BaseRefreshHelper<IBaseRefreshContact.IBaseRefreshView> mBaseHeaderHelper;

    @Override
    public void initHeader(Bundle savedInstanceState) {
        super.initHeader(savedInstanceState);
        initRefresh(savedInstanceState);
    }

//    @Override
//    public void initLoad() {
//        mSpinKitView = mBaseHeaderHelper.initLoadProgress();
//        setLoadProgress();
//    }

    @Override
    public void initRefresh(Bundle saveInstanceStatus) {
        mBaseHeaderHelper = new BaseRefreshHelper<IBaseRefreshContact.IBaseRefreshView>(this);
        mSwipeRefreshLayout = mBaseHeaderHelper.initRefreshLayout();
//        initLoad();
        setRefreshHeader();
    }

    @Override
    public int getRefreshId() {
        return R.id.pre_refresh;
    }

//    @Override
//    public int getLoadProgressId() {
//        return mBaseHeaderHelper.getDefaultProgressId();
//    }
//
//    @Override
//    public void setLoadProgress() {
//        mBaseHeaderHelper.setLoadProgress();
//    }

    @Override
    public void setRefreshHeader() {
        mBaseHeaderHelper.setRefreshHeader();
    }

    @Override
    public SwipeRefreshLayout getRefreshLayout() {
        return mSwipeRefreshLayout;
    }


    @Override
    public void autoRefresh() {
        if (mSwipeRefreshLayout == null) {
            onRefreshBegin(null);
            return;
        }

        mSwipeRefreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
            onRefreshBegin(mSwipeRefreshLayout);
            }
        },500);
    }



    //    @Override
//    public void autoLoad() {
//        mBaseHeaderHelper.autoLoad();
//    }

    @Override
    public void refreshComplete() {
        if (mSwipeRefreshLayout == null) {
            return;
        }
        mSwipeRefreshLayout.setRefreshing(false);
    }

//    @Override
//    public void loadComplete() {
//        mBaseHeaderHelper.loadComplete();
//    }
}
